{% load static %}
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title></title>
    <link rel="stylesheet" href="{% static 'js/lib/layui/css/layui.css' %}">
    <link rel="stylesheet" href="{% static 'css/common.css' %}">
</head>
<body>

<div class="layui-container" style="margin-top: 30px">
    <div class="layui-row">
        <div style="margin: 10px 0 20px;">
            <div style="margin-top: 10px;margin-bottom: 10px;">
                <label style="font-weight: bold;color: #333333">数据挖掘模型名称</label>
            </div>
            <select name="model_name" id="model_name"
                    class="btn btn-default dropdown-toggle my-select" style="width: 100%">
                <option value="" style="color: gray;display: none;">请选择基础模型类型</option>
                {% for foo in base_model_obj %}
                    <option value="{{ foo.name }}">{{ foo.name }}</option>
                {% endfor %}
            </select>

        </div>

        <div style="margin: 10px 0 20px;">
            <div style="margin-top: 10px;margin-bottom: 10px;">
                <label style="font-weight: bold;color: #333333">参数(节点标签)</label>
            </div>
            <input type="text" name="label" id="label" class="layui-input">
        </div>
        <div style="margin: 10px 0 20px;">
            <div style="margin-top: 10px;margin-bottom: 10px;">
                <label style="font-weight: bold;color: #333333">参数(节点唯一标识)</label>
            </div>
            <input type="text" name="uuid" id="uuid" class="layui-input">
        </div>
        <div style="margin: 10px 0 20px;">
            <div style="margin-top: 10px;margin-bottom: 10px;">
                <label style="font-weight: bold;color: #333333">模型配置</label>
            </div>
            <input type="text" name="configuration" id="configuration" class="layui-input">
        </div>
    </div>

    <div>
        <button type="submit" class="my-btn" style="float: right;" id="sub"> 确认</button>
    </div>
</div>
</div>

<script type="text/javascript" src="{% static 'js/jquery.min.js' %}"></script>
<script src="{% static 'js/lib/layui/layui.js' %}"></script>
<script>
    function process_file(obj) {
        $('#file_name').html($('#choose_file').val().split('\\').slice(-1))
    }

    $('#sub').click(function () {
        var name = $('#model_name').val();
        var label = $('#label').val();
        var uuid = $('#uuid').val();
        var configuration = $('#configuration').val();

        if (name === '') {
            alert("模型名称不能为空！！！");
        } else if (label === '') {
            alert("参数(节点标签)不能为空！！！");
        } else if (uuid === '') {
            alert("参数(节点唯一标识)不能为空！！！");
        } else if (configuration === '') {
            alert("模型配置不能为空！！！");
        } else {
            $.ajax({
                url: '{% url 'model_import' %}',
                type: 'post',
                data: {'name': name, 'label': label, 'uuid': uuid, 'configuration': configuration},
                success: function (res) {
                    if (res["code"] == "1") {
                        window.parent.layer.closeAll();
                        window.parent.location.href = '{% url "data_mining_model" %}?import_sign=0';
                    } else {
                        alert(res["msg"]);
                    }
                }
            })
        }
    });
</script>

</body>
</html>